#ifndef _NET_KIT_FD_EPOLL_H_
#define _NET_KIT_FD_EPOLL_H_

#include <sys/epoll.h>

namespace NetKit
{
class Epoll
{
public:
	Epoll(int maxFd = 1024);
	~Epoll();
	void AddReadEvent(int fd);
	void AddWriteEvent(int fd);
	void ModWriteEvent(int fd);
	void ModReadEvent(int fd);
	void ModReadWriteEvent(int fd);
	void DelEvent(int fd);
	int EpollWait(int timeout_ms);

public:	//for iterator m_pEvents
	//void First(){m_iIterIdx = 0;}
	//void Next(){++m_iIterIdx;}
	//bool IsDone(int wantCount){return wantCount<=m_iIterIdx;}
	void GetFdEvents(int index, int& fd, int& events);
private:
	void Grow(int size);
	
private:
	int m_epfd;
	struct epoll_event m_ev;
	struct epoll_event* m_pEvents;	
	int m_iEventNum;
	int m_iEventArraySize;
};

}

#endif //_NET_KIT_FD_EPOLL_H_
